﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using SynergyControls;
using SynergyLib.DSP;
using SharpDX.XAudio2;

namespace XAudio2Controls
{
    public class ShelvingPeakFilterPanel : EffectsPanel, IEffectParams
    {
        public float G {get {return DialAngle1/360 * 24.4f;}}
        public float Fc { get { return DialAngle2 / 360; } }
        public float Q { get { return (float)Math.Abs(DialAngle3 / 360) * Submixer.VoiceDetails.InputSampleRate; } }

        public ShelvingPeakFilter spFilter { get; set; }

        static ShelvingPeakFilterPanel()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ShelvingPeakFilterPanel), new FrameworkPropertyMetadata(typeof(EffectsPanel)));
        }
        public ShelvingPeakFilterPanel(SubmixVoice submixer, Collection<EffectDescriptor> fxChainReference)
        {
            FxChain = fxChainReference;
            EffectParams = this;
            effectType = EffectTypes.ShelvingPeakFilter;
            Submixer = submixer;
            this.Effect = new ShelvingPeakFilter();
            spFilter = (ShelvingPeakFilter)Effect;
            this.effectDescriptor = new EffectDescriptor(Effect);

        }
        protected override void UpdateParameters()
        {
            spFilter.Parameters = new ShelvingPeakFilterParams() 
            {
            G = this.Param1,
            Fc = this.Param2,
            Q = this.Param3,
            };            
        }
            
        #region IEffectParams
        public float Param1
        { 
            get
            {
                ParamLabel1Content = GetParam1Readout();
                return G;
            } 
        }
        public float Param2
        {
            get
            {
                ParamLabel2Content = GetParam2Readout();
                return Fc;
            }
        }
        public float Param3
        {
            get
            {
                ParamLabel3Content = GetParam3Readout();
                return Q;
            }
        }
        public float Param4
        {
            get;
            set;
        }

        public string ParamName1
        {
            get
            {
                return "G";
            }
        }
        public string ParamName2
        {
            get 
            {
                return "Fc";
            }
        }
        public string ParamName3
        {
            get
            {
                return "Q";
            }
        }
        public string ParamName4
        {
            get
            {
                return GetParam4Readout();
            }
        }

        public string GetParam1Readout()
        {
            return ((Math.Round(G, 4))).ToString() + "db";
        }
        public string GetParam2Readout()
        {
            return (Math.Round(Fc, 3)).ToString() + "Hz";
        }
        public string GetParam3Readout()
        {
            return (Math.Round(Q, 2)).ToString() + "1/Q";
        }
        public string GetParam4Readout()
        {
            return null;
        }
        #endregion IEffectParams
    }
}
